<template>
  <a-upload
    v-model:file-list="fileList"
    name="file"
    action="/jeecg-boot/cable/plan4/importExcel"
    :headers="headers"
    @change="handleChange"
    :showUploadList="false"
  >
    <a-button>
      <upload-outlined />
      antd上传
    </a-button>
  </a-upload>
</template>
<script lang="ts" setup>
import { message } from 'ant-design-vue'
import { UploadOutlined } from '@ant-design/icons-vue'
import type { UploadChangeParam } from 'ant-design-vue'
import { useAuthStore } from '@/store/auth'

const emits = defineEmits(['antdUploaded'])
const handleChange = (info: UploadChangeParam) => {
  if (info.file.status !== 'uploading') {
    console.log(info.file, info.fileList)
  }
  if (info.file.status === 'done') {
    message.success(`${info.file.name} file uploaded successfully`)
    emits('antdUploaded')
  } else if (info.file.status === 'error') {
    message.error(`${info.file.name} file upload failed.`)
  }
}

const fileList = ref([])

const { token } = useAuthStore()
const headers = {
  'X-Access-Token': token
}
</script>
